<template>
  <div class="c-ph24 c-pt20 c-bg-white">
    <div class="tinymce-text c-wb-ba c-contexty-scroll" :class="[cfg.isCopyPicture == 0 ? 'closeBig' : 'aCloseBig', cfg.isCopy == 0 ? 'copyNot' : '']" v-html="analysis"></div>
    <!-- 音频内容 -->
    <div v-for="(item,index) in hwRelate" :key="index">
      <div v-if="item.type == 3" class="c-pt20">
        <aplayer @play="playAplayer" preload="auto" :volume="1" repeat="repeat-one" :music="{
          artist:' ',
          title: item.title,
          src: isiOS ? item.audioM3u8 : item.audioM4a,
          pic:require('@/assets/i/wap/clockIn/audio_cover_d.png'),
        }" />
      </div>
      <!-- 视频内容 -->
      <div v-else-if="item.type == 2" class="c-pt20">
        <div :id='"myVideo" + index' class="clock-video c-pz1 c-w100-im" style="height:auto;"></div>
      </div>
    </div>
    <loading-status-tem :noData="(!analysis||analysis=='')&&hwRelate.length==0" :noDataText="'暂无解析'"></loading-status-tem>
  </div>
</template>

<script>
import { utilJs } from "@/utils/common.js";
import VueAPlayer from "@/plugin/vue-aplayer/vue-aplayer.vue";
import { getXgplayer } from "@/utils/xgplayerJs.js";
import loadingStatusTem from "@/components/templates/common/loadingStatusTem.vue";
let curHwId = ''; //当前作业ID
export default {
  name: "SimpleQueResult",
  components: {
    Aplayer: VueAPlayer,
    loadingStatusTem
  },
  props: [],
  data() {
    return {
      theme: localStorage.getItem("colorName") ? localStorage.getItem("colorName") : "mb5_default",
      cfg: JSON.parse(localStorage.getItem("cfg")),
      analysis: '',
      hwRelate:[]
    };
  },
  created() {
    utilJs.appShare(this);
  },
  mounted() { },
  methods: {
    initTcPlayer(index, mp4Url, videoM3u8, poster) {
      if (mp4Url == '' || mp4Url == null) {
        mp4Url = videoM3u8 ? videoM3u8 : '';
      }
      if (videoM3u8 == '' || videoM3u8 == null) {
        videoM3u8 = mp4Url ? mp4Url : '';
      }
      let videoObj = {
        videoMp4: mp4Url,
        videoM3U8: videoM3u8,
        autoplay: false,
        fluid: false,
        isCssFullScreen: true,
        poster: poster || 'https://kposshzcdn.ckjr001.com/admin/material/9_material_admin/image/assets/i/wap/clockIn/video-bg2.png',
      }
      let dId = 'myVideo' + index;
      setTimeout(() => {
        getXgplayer(dId, videoObj);
      }, 10);
    },
    playAplayer(src) {
      if (typeof src == 'string') {
        let arr = document.getElementsByTagName("video");
        for (let i = 0; i < arr.length; i++) {
          if (arr[i].src !== src) {
            arr[i].pause();
          }
        }
      }
    },
    //获取结果信息
    getAnwerResultInfo() {
      utilJs.getMethod(
        global.apiurl + "signCard/answerAnalyze/" + curHwId,
        res => {
          this.analysis = res.analysis;
          this.hwRelate = res.hwRelate
          for (let i = 0; i < res.hwRelate.length; i++) {
            if (res.hwRelate[i].type == 2) {
              this.initTcPlayer(i, res.hwRelate[i].content, res.hwRelate[i].content, res.hwRelate[i].videoM3u8, res.hwRelate[i].videoCover);
            }
          }
        }
      );
    },

    //分享
    wechatShare: function () {
      let title = window.localStorage.getItem("companyName");
      let shareImg = window.localStorage.getItem("shareLogo");
      let shareDesc = window.localStorage.getItem("shareDesc");
      let shareUrl = `${window.location.href.split("#")[0]}#${this.$route.path}?refereeId=${localStorage.getItem("userId")}`
      let shareIndexData = {
        shareUrl,
        title,
        shareImg,
        shareDesc,
      };
      let shareData = localStorage.getItem("homeWorkShare") ? JSON.parse(localStorage.getItem("homeWorkShare")) : shareIndexData;
      utilJs.wechatConfig(
        shareData.shareUrl,
        shareData.title,
        shareData.shareImg,
        shareData.shareDesc,
        function () { },
        true
      );
    },
    //手机端分享
    appShare: function () {
      let title = window.localStorage.getItem("companyName");
      let shareImg = window.localStorage.getItem("shareLogo");
      let shareDesc = window.localStorage.getItem("shareDesc");
      let shareUrl = `${window.location.href.split("#")[0]}#${this.$route.path}?refereeId=${localStorage.getItem("userId")}`
      let shareIndexData = {
        shareUrl,
        title,
        shareImg,
        shareDesc,
      };
      let shareData = localStorage.getItem("homeWorkShare") ? JSON.parse(localStorage.getItem("homeWorkShare")) : shareIndexData;
      utilJs.appShareTrue(
        shareData.title,
        shareData.shareImg,
        shareData.shareUrl,
        shareData.shareDesc
      );
    }
  },
  activated() {
    setDocumentTitle("简答题解析");// eslint-disable-line
    curHwId = this.$route.query.curHwId;
    this.examInfo = {};
    this.answerSheet = []
    this.getAnwerResultInfo();
    this.wechatShare();
  },
  deactivated() { }
};
</script>

<style scoped>
.closeBig >>> p > img,
.closeBig >>> section > img,
.closeBig >>> div > img,
.closeBig >>> img {
  pointer-events: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -webkit-user-select: none;
  -o-user-select: none;
  user-select: none;
}
.aCloseBig >>> p > a > img,
.aCloseBig >>> section > a > img,
.aCloseBig >>> div > a > img {
  pointer-events: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -webkit-user-select: none;
  -o-user-select: none;
  user-select: none;
}
</style>
